package com.zjx.educms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zjx.educms.entity.CrmBanner;
import com.zjx.educms.mapper.CrmBannerMapper;
import com.zjx.educms.service.CrmBannerService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2025-02-18
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {

    //查询所有banner
    @Cacheable(value = "banner",key = "'selectIndexList'")
    @Override
    public List<CrmBanner> selectAllBanner() {
        //根据id进行降序排序，显示排序之后前两条记录
//        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
//        wrapper.orderByDesc("id");
//        //last方法，拼接sql语句
//        wrapper.last("limit 2");
        List<CrmBanner> list = baseMapper.selectList(null);
        return list;
    }

    @Override
    public void pageBanner(Page<CrmBanner> pageParam, CrmBanner crmBanner) {
        QueryWrapper<CrmBanner> crmBannerQueryWrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(crmBanner.getTitle())){
            crmBannerQueryWrapper.like("title",crmBanner.getTitle());
        }

        baseMapper.selectPage(pageParam,crmBannerQueryWrapper);
    }
}
